var code = "";
$("#indexC").on('click', '#medicalRecords', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/medicalRecords";
});
$("#indexC").on('click', '#doctorAdvice', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/doctorAdvice";
});
$("#indexC").on('click', '#scoreRecord', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/scoreRecord";
});
$("#indexC").on('click', '#integralRecord', function () {
    window.location.href = Feng.ctxPath + '/integralMallWeixin/integralRecord/' + "1";
});
$("#indexC").on('click', '#scoreShopping', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/scoreShopping";
});
$("#indexC").on('click', '#memberRecommendation', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/memberRecommendation";
});
$("#indexC").on('click', '#caseDetails', function () {
    window.location.href = Feng.ctxPath + "/integralMallWeixin/caseDetails";
});
$("#indexC").on('click', '#outLogin', function () {
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/logout",
        type: "get",
        success: function (data) {
            window.location.href = Feng.ctxPath + "/integralMallWeixin/logincus";
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

function homeSignIn(reservationsId) {
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/signInScore",
        type: "post",
        data: {"reservationsId": reservationsId},
        success: function (data) {
            if (data == 1) {
                alert("签到成功,您已获得积分200！");
                getPersonalCenter();
            } else {
                alert("您今日已签到过！");
            }
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
}

function getPersonalCenter() {
    if (window.location.href.indexOf("code") != -1) {
        code = window.location.href.split("code=")[1].split("&state")[0];
    }
    $.ajax({
        url: Feng.ctxPath + "/integralMallWeixin/getPersonalCenter",
        type: "POST",
        data: {"code": code},
        success: function (data) {
            if (data == '' || data == null) {
                window.location.href = Feng.ctxPath + "/integralMallWeixin/logincus";
                return false;
            }
            document.getElementById("openId").value = data.openId;
            document.getElementById("reservationsId").value = data.reservationsId;
            $(".homePage").css({
                'background': 'url("https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/BlueAndWhite.png") no-repeat',
                'background-size': '100% 100%'
            });
            var html =
                "<div class='homeHeadPortrait'>" +
                "    <div class='homeCircle'>" +
                "        <div class='headPortraitCircle'>" +
                "            <img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/QQ20190826112636.jpg' style='width: 100%;border-radius: 50%;'>" +
                "        </div>" +
                "        <div style='font-size: 18px;font-weight: bold'>" + data.name + "</div>" +
                "    </div>" +
                "    <div class='homeBaiDi'>" +
                "        <div>" +
                "            <img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/zuanshitb.png' alt=''>" +
                "            <div>" + data.vipLevelName + "</div>" +
                "        </div>" +
                "        <div>" +
                "            <img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/jifentb.png' alt=''>" +
                "            <div><span style='font-size: 16px;'>" + data.scoreBalance + "</span>积分</div>" +
                "        </div>" +
                "        <div onclick='homeSignIn(" + '"' + data.reservationsId + '"' + ")' >" +
                "            <img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/jifentb.png' alt=''>" +
                "            <div>签到</div>" +
                "        </div>" +
                "    </div>" +
                "</div>" +
                "<div class='homeInformation'>" +
                "    <div class='informationDiv'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/qianbaotb.png' alt='' style='width: 18px;margin-right: 12px;'><span>余额</span></div>" +
                "        <div>" + data.actualAccountBalance + "元</div>" +
                "    </div>" +
                "    <div class='informationDiv'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/qianbaotb.png' alt='' style='width: 18px;margin-right: 12px;'><span>返现余额</span></div>" +
                "        <div>" + data.scoreBalancex + "元</div>" +
                "    </div>" +
                "    <div class='informationDiv'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/binglitb.png' alt=''><span>病历号</span></div>" +
                "        <div>" + data.medicalRecordNumber + "</div>" +
                "    </div>" +
                "    <div class='informationDiv' id='caseDetails'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/yizhutb.png' alt=''><span>病历记录</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='doctorAdvice'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/yizhutb.png' alt=''><span>医嘱信息</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='medicalRecords'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/jilu4.png' alt=''><span>就诊记录</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='scoreRecord'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/jilu4.png' alt=''><span>积分记录</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='integralRecord'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/IntegralRecord.png' alt=''><span>兑换记录</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='scoreShopping'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/shopping.png' alt='' style='width: 18px;margin-right: 12px;'><span>积分商城</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv' id='memberRecommendation'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/jilu4.png' alt='' style='width: 18px;margin-right: 12px;'><span>会员推荐</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "    <div class='informationDiv'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/shoujitb.png' alt='' style='width: 19px;margin-right: 11px;'><span>手机号</span></div>" +
                "        <div>" + data.phone + "</div>" +
                "    </div>" +
                "    <div class='informationDiv'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/dizhitb.png' alt=''><span>地址</span></div>" +
                "        <div>" + data.address + "</div>" +
                "    </div>" +
                "    <div class='informationDiv' id='outLogin'>" +
                "        <div><img src='https://pynnn.oss-cn-hangzhou.aliyuncs.com/one/dizhitb.png' alt=''><span>退出</span></div>" +
                "        <div><span class='glyphicon glyphicon-menu-right'></span></div>" +
                "    </div>" +
                "</div>";
            $("#indexC").html(html);
        },
        error: function (data) {

        }
    });
}

$(function () {
    getPersonalCenter();
});